﻿using System.Collections.Generic;

namespace Microsoft.Xna.Framework
{
    internal class UpdateOrderComparer : IComparer<IUpdateable>
    {
        #region Static Operations

        public static readonly UpdateOrderComparer Default = new UpdateOrderComparer();

        #endregion

        #region Implementation of IComparer<in IUpdateable>

        /// <summary>
        /// 	Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <returns>
        /// 	A signed integer that indicates the relative values of <paramref name = "x" /> and <paramref name = "y" />, as shown in the following table.Value Condition Less than zero<paramref
        /// 	name = "x" /> is less than <paramref name = "y" />.Zero<paramref name = "x" /> equals <paramref name = "y" />.Greater than zero<paramref
        /// 	name = "x" /> is greater than <paramref name = "y" />.
        /// </returns>
        /// <param name = "x">The first object to compare.</param>
        /// <param name = "y">The second object to compare.</param>
        public int Compare(IUpdateable x, IUpdateable y)
        {
            if (x == null && y == null)
            {
                return 0;
            }
            if (x != null)
            {
                if (y == null)
                {
                    return -1;
                }
                if (x.Equals(y))
                {
                    return 0;
                }
                if (x.UpdateOrder < y.UpdateOrder)
                {
                    return -1;
                }
            }
            return 1;
        }

        #endregion
    }
}